<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-switch/css/bootstrap-switch.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/multiselect-master/css/multiselect.css">
</head>
<style>
</style>
<body id="body" style="padding-bottom: 90px; background-color: #ECF0F5;">
	<div class="modal-content">
		<div class="modal-body">
			<div class="row">
				<div class="col-xs-5">
					<select id="pName" name="from" class="js-multiselect form-control" style="height: 150px;" multiple="multiple">
					</select>
				</div>
				<div class="col-xs-2">
					<button type="button" id="js_right_All_1" class="btn btn-block">
						<i class="glyphicon glyphicon-forward"></i>
					</button>
					<button type="button" id="js_right_Selected_1" class="btn btn-block">
						<i class="glyphicon glyphicon-chevron-right"></i>
					</button>
					<button type="button" id="js_left_Selected_1" class="btn btn-block">
						<i class="glyphicon glyphicon-chevron-left"></i>
					</button>
					<button type="button" id="js_left_All_1" class="btn btn-block">
						<i class="glyphicon glyphicon-backward"></i>
					</button>
				</div>
				<div class="col-xs-5">
					<select name="to" id="pIds" class="form-control" style="height: 150px;" multiple="multiple"></select>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script src="${pageContext.request.contextPath}/plugins/multiselect-master/js/multiselect.min.js"></script>

<script>
	var lock = false;
	var id = "${map['id']}";
	var index = parent.layer.getFrameIndex(window.name);

	$(function() {
		$.ajax({
			url : "${pageContext.request.contextPath}/selectPropertyPersonnelByAll",
			type : "post",
			dataType : "json",
			success : function(map) {
				var list = map['list'];
				var html = "";
				for (var i = 0; i < list.length; i++) {
					html += "<option value='"+list[i].id+"'>" + list[i].name + "</option>";
				}
				$("#pName").html(html);
				$('#pName').multiselect({
					right : '#pIds',
					rightAll : '#js_right_All_1',
					rightSelected : '#js_right_Selected_1',
					leftSelected : '#js_left_Selected_1',
					leftAll : '#js_left_All_1'
				});
			}
		});
	});

	//添加或修改
	function updateWorkorderByPersonnel() {
		layer.confirm("是否确定推送？", function(index) {
			lock = true;
			var dom = document.getElementById("pIds");
			var ids = "";
			for (var i = 0; i < dom.length; i++) {
				ids += "," + dom.children[i].value;
			}
			if (ids == '') {
				layer.alert("请选择人员！");
				lock = false;
				return;
			}
			$.ajax({
				url : "${pageContext.request.contextPath}/updatePropertyWorkorder",
				type : "post",
				data : {
					id : id,
					pId : ids.substring(1),
					state : '2'
				},
				dataType : "json",
				success : function(data) {
					if (data.result === 1) {
						layer.msg('操作成功！', {
							icon : 1,
							time : 800
						});
						setTimeout(function() {
							parent.query();
							parent.layer.close(index);
						}, 1000);
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
						lock = false;
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
					lock = false;
				}
			});
		});
	}

	function update() {
		if (!lock) {
			updateWorkorderByPersonnel();
		}
	}
</script>
</html>
